package sudoku;

import java.io.*;
import java.net.*;

public class Client {

	static int portServeur;
	String pseudo;
	String adresseIsae;
	Socket clientSocket;
	GrilleSudoku grillePartagee;

	public Client(String ps, String p, String nom){
		this.portServeur = Integer.parseInt(ps);
		this.pseudo = p;
		this.adresseIsae = nom;

		int i = 1;

		try {
			String sentence;
			String modifiedSentence;
			BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

			clientSocket = new Socket(adresseIsae, portServeur );
			
			//Reception des objets
			ObjectInputStream input = new ObjectInputStream(clientSocket.getInputStream());
			try {
				GrilleSudoku grilleAPartager = (GrilleSudoku) input.readObject();
				this.grillePartagee = grilleAPartager;
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
			BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			sentence = inFromUser.readLine();
			if (i==1){sentence = "le jeu peut commencer"; i--;}
			outToServer.writeBytes(sentence + '\n');
			modifiedSentence = inFromServer.readLine();
			System.out.println("Recu: " + modifiedSentence);
			clientSocket.close();
			} 
		catch (UnknownHostException e) {e.printStackTrace();} 
		catch (IOException e) {e.printStackTrace();}
	}








}
